const mysql = require('mysql2/promise')
const config = require('./config')

const pool = mysql.createPool(config)

module.exports = async (sql, values) => {
  try {
    const [rows] = await pool.execute(sql, values || [])
    return rows
  } catch (error) {
    console.error('Database query error:', error)
    throw error
  }
}